/**
 * AI假服务器
 */
class AIServer {
	private static instance: AIServer;
	public static getInstance(): AIServer {
		if (this.instance == null) {
			this.instance = new AIServer();
		}
		return this.instance;

	}


	public constructor() {
		this.playpointTmp = new egret.Point(0, 0);

	}






	private userId;

	private c = serverConfig.config;

	protected playpointTmp: egret.Point;

	protected p0Tmp = new egret.Point(0, 0);
	protected p1Tmp = new egret.Point(0, 0);
	/**玩家管理 */
	private userMgr = AIUserMgr.getInstance();
	public yaogan;
	public roomInfo = {
		gameOver: false,
		countDown: this.c.maxGameTime * 60,
		roomUser: [],
		roomLine: [],
		roomProps: [],
		AINumbers: 0,
		userNumbers: 0,
		opentime: 0,
		startTime: -1,
		roomId: -1
	};
	/**改变青蛙states状态 */
	public setUserStates(userid, type) {
		let player = this.userMgr.get(userid);

		if (player == null) {
			return;
		}

		player.states = type;
	}
	/**重置青蛙states状态 */
	public resetUserStates(userid) {
		let player = this.userMgr.get(userid);

		if (player == null) {
			return;
		}

		player.states = 0;
	}
	/**获取青蛙states状态 */
	public getUserStates(userid) {
		let player = this.userMgr.get(userid);

		if (player == null) {
			return;
		}

		return player.states;
	}
	private tmpShootPoint = new egret.Point();
	/**发射出舌头 */
	public shoot(userid, dir) {

		let player = this.userMgr.get(userid);

		if (player == null) {
			return;
		}
		if (player.shootStates.isShoot == true) {
			console.log("玩家的已在射擊狀態...");
			return;
		}
		this.tmpShootPoint.setTo(dir.x, dir.y);
		this.tmpShootPoint.normalize(player.lineLength * frogConfig.independent_Long_tongue_coefficient);

		//  let vecdir = new Vector2(tmpMessage.targetx, tmpMessage.targety).normalize(player.speed);

		player.shootStates.isShoot = true;
		player.shootStates.point.y = Math.floor(player.y + this.tmpShootPoint.y);
		player.shootStates.point.x = Math.floor(player.x + this.tmpShootPoint.x);
	}


	/*判断一下是否有玩家被射中*/
	checkShootPlayer(player) {

		if (player.shootStates.isShoot == false)
			return;
		let frog = webNetworkMananger.getInstance().gameSceneRec.m_createAllFrogs.findFrogById(player.userId);

		let minUserDistance = 10000;
		let minLineUser;
		let minprop;
		for (var i = 0; i < this.roomInfo.roomUser.length; ++i) {

			if ((Util.getInstance().isNull(this.roomInfo.roomUser[i].isAI) && this.roomInfo.roomUser[i].isAI) || this.roomInfo.roomUser[i].death.isDeath || this.isLineTogether(this.roomInfo.roomUser[i], player))
				continue;

			if (this.roomInfo.roomUser[i].userId == player.userId)
				continue;
			//找到舌头接触到所有玩家，找出其中最近的
			//  let nowDistance = this.checkIsOnALine(this.roomUser[i].lineLength, this.roomUser[i], player.shootStates.point);
			if (this.NewcheckIsOnALine(this.roomInfo.roomUser[i].lineLength, this.roomInfo.roomUser[i], player, player.shootStates.point)) {

				this.playpointTmp.setTo(player.x, player.y);
				let nowDistance = Util.getInstance().getDistance(this.roomInfo.roomUser[i], this.playpointTmp);
				if (nowDistance < minUserDistance) {
					minUserDistance = nowDistance;
					minLineUser = this.roomInfo.roomUser[i];
					continue;
				}
			}


		}
		//找出舌头碰到的最近的道具
		for (var i = 0; i < this.roomInfo.roomProps.length; ++i) {
			if (this.roomInfo.roomProps[i].isisUsed)
				continue;
			if (this.NewcheckIsOnALine(50, this.roomInfo.roomProps[i], player, player.shootStates.point)) {
				this.playpointTmp.setTo(player.x, player.y)
				let nowDistance = Util.getInstance().getDistance(this.roomInfo.roomProps[i], this.playpointTmp);
				if (nowDistance < minUserDistance) {
					minUserDistance = nowDistance;
					minprop = this.roomInfo.roomProps[i];
					continue;
				}
			}
		}

		if (minLineUser != null) {
			let distance = MathUtils.distance(player.x, player.y, minLineUser.x, minLineUser.y);
			if (minLineUser.ishadLine || minLineUser.frogType != player.frogType) {
				AIPropsMgr.getInstance().changeSinglePlayerState({ type: 9 }, player);//舔到异色青蛙
				//frog.lollAnime(distance);
				this.resetPlayerShoot(player);

				return;
			}
			else {

				var line = LineManager.getInstance().getOneLine(player.userId, minLineUser.userId);
				if (line == null) {
					console.log("线已经满了");
					return;
				}
				line.userOneId = player.userId;
				line.userTwoId = minLineUser.userId;
				line.isUsed = true;
				line.type = minLineUser.frogType;

				minLineUser.ishadLine = true;
				player.ishadLine = true;
				minLineUser.otherLineUser = line.userOneId;
				player.otherLineUser = line.userTwoId;
				this.roomInfo.roomLine.push(line);
				frog.lollAnime(distance);
				this.resetPlayerShoot(player);
				return;
			}
		}
		else {
			if (minprop == null) {
				frog.lollAnime(0);
			}
			this.resetPlayerShoot(player);
			// this.broadcastShootMessage(player.userId);
		}
		//如果舔到道具调用飞过去方法
		if (minprop != null) {
			if (player.isAI) {//AI吐到道具有问题
				return;
			}
			if (webNetworkMananger.getInstance().gameSceneRec != null) {
				if (webNetworkMananger.getInstance().gameSceneRec.m_createAllFrogs != null) {
					if (frog != null) {
						let distance = MathUtils.distance(player.x, player.y, minprop.x, minprop.y);

						frog.lollAnime(distance - 50);
						frog.lickProp(minprop.x, minprop.y)
						this.resetPlayerShoot(player);
					}
				}
			}

		}
		else { this.resetPlayerShoot(player); }
	}
	resetPlayerShoot(player) {
		player.shootStates.isShoot = false;
		player.shootStartTime = 0;
		player.shootStates.point.x = 0;
		player.shootStates.point.y = 0;

	}
	/**判断一下线已经链接 */
	isLineTogether(p1, p2) {


		if (p1.otherLineUser != null) {
			if (p1.otherLineUser == p2.userId)
				return true;
			else
				return false;
		}
		else {
			return false;
		}


	}

	NewcheckIsOnALine(userSize, something, usrend, usrstart) {
		/**点到线的距离 */
		var pointToLineLength = Util.getInstance().getPointToLineDistance(usrend, usrstart, something);
		var tlenght = 50;
		return pointToLineLength < tlenght ? true : false;
	}


	/**断掉玩家指定的线 */
	public breakLine(theUserid) {
		let roomUser = this.roomInfo.roomUser;
		let len = roomUser.length - 1;
		let tmpUser = null
		for (var i = len; i >= 0; i--) {
			if (roomUser[i].userId == theUserid) {
				tmpUser = roomUser[i];
			}
		}

		if (tmpUser == null) {
			// console.log("房间内没有该玩家");
			return;
		}
		if (tmpUser.death.isDeath == true) {
			// console.log("玩家已经死了...");
			return;
		}
		let tmpline = LineManager.getInstance().getUserLine(this.roomInfo.roomLine, tmpUser);

		if (Util.getInstance().isNull(tmpline)) {
			// console.log("玩家的綫不存在...");
			return;
		}

		let playtwo = null;
		for (var i = len; i >= 0; i--) {
			if (roomUser[i].userId == tmpUser.otherLineUser) {
				playtwo = roomUser[i];
			}
		}
		if (playtwo != null) {
			/**青蛙下个目标点 */
			let p0 = this.nextpoint(tmpUser)
			let p1 = this.nextpoint(playtwo)
			/**青蛙最大舌长 */
			let maxDistance = playtwo.lineLength + tmpUser.lineLength + 0.5;
			/**青蛙下个目标间距离 */
			let nowDistance = Util.getInstance().getPointDistance(p0, p1)
			/**判断青蛙下个目标点是否是向外移动 如果是则弹开 0.5为误差值 */
			if (nowDistance >= maxDistance) {
				if (playtwo.isAI) {
					playtwo.targetdir.setTo(0, 0)
				}
				else {
					playtwo.targetdir.x = 0;
					playtwo.targetdir.y = 0;
				}

				if (tmpUser.isAI) {
					tmpUser.targetdir.setTo(0, 0)
				}
				else {
					tmpUser.targetdir.x = 0;
					tmpUser.targetdir.y = 0;
				}
				this.countPoint(tmpUser, playtwo);

			}
			var userOneInfo = this.userMgr.get(tmpline.userOneId);
			var userTwoInfo = this.userMgr.get(tmpline.userTwoId);
			LineManager.getInstance().lineLongerMax(userOneInfo, userTwoInfo);
		}
		LineManager.getInstance().recoveryLine(tmpline, this.roomInfo.roomLine);
		return;

	}

	/**检测下个目标点 */
	public nextpoint(player) {
		var point = null;
		if (player.isAI) {
			//获取ai下个目标点位置
			point = MathUtils.calculateNextPointEx(player.x, player.y, player.targetdir.x, player.targetdir.y, player.speed, false)
		}
		else {
			/**获取玩家下个目标点位置 */
			if (player.targetdir == null)
			{ return; }
			var target = {
				x: player.targetdir.x,
				y: player.targetdir.y
			};
			let dir = egret.Point.create(target.x, target.y);
			//判断玩家的射击
			dir.normalize(player.speed);
			let nextX = player.x + dir.x
			let nextY = player.y + dir.y
			point = new egret.Point(nextX, nextY);
		}
		return point

	}

	private countPointP0tmp = new egret.Point(0, 0);
	private countPointP1tmp = new egret.Point(0, 0);

	/**断线弹开动画 */
	public countPoint(playone, playertwo) {
		this.countPointP0tmp.setTo(playone.x, playone.y);
		this.countPointP1tmp.setTo(playertwo.x, playertwo.y);
		var point1: any = LineManager.getInstance().calulatePopDir1(this.countPointP0tmp, this.countPointP1tmp);
		var point2: any = LineManager.getInstance().calulatePopDir1(this.countPointP1tmp, this.countPointP0tmp);

		LineManager.getInstance().frogchangepoint(playone, point1)
		LineManager.getInstance().frogchangepoint(playertwo, point2)
		LineManager.getInstance().getflicktween(point1, playone);
		LineManager.getInstance().getflicktween(point2, playertwo);

	}
	/**玩家移动 */
	public clientMove(data) {
		var point = data.target;
		AIUserMgr.getInstance().currentPlayer.targetdir = point;
	}

	public setGuidPoint(point) {
		AIUserMgr.getInstance().currentPlayer.target.x = point.x;
		AIUserMgr.getInstance().currentPlayer.target.y = point.y;
	}
	public ClientFly(data) {
		var point = data.target;
		var client = AIUserMgr.getInstance().currentPlayer
		client.x = point.x;
		client.y = point.y;
		client.targetdir.x = point.x;
		client.targetdir.y = point.y;
	}


	public getRoomUsers() {
		return this.roomInfo.roomUser;
	}

	/**玩家变色 */
	public changeFrogType() {
		var player = AIUserMgr.getInstance().currentPlayer;
		if (player == null) {
			console.log("playerIsNo");
			return;
		}
		if (player.death.isDeath == true)
			return;
		player.frogType = player.frogType == this.c.maxtype ? 0 : player.frogType + 1;
	}

	/**房间初始化 */
	public roomInit() {

		LineManager.getInstance().createLines();
		this.userJoin();
		/**创建AI */
		if (DataProl.tuanduizhan) {
			serverAIMgr.getInstance().creatAIs(10);
		} else {
			serverAIMgr.getInstance().creatAIs(15);
			//serverAIMgr.getInstance().creatAIs(2);
		}
		this.createRoomsProps();
		var roomUser = AIUserMgr.getInstance().getAllUser();
		this.enterRoom(roomUser[DataProl.account]);
		this.gameStart();
	}

	/**退出房间初始化 */
	public roomRest() {
		LineManager.getInstance().restLines();
		AIUserMgr.getInstance().restUsers();
		serverAIMgr.getInstance().restAIs();
		AIPropsMgr.getInstance().restAllProps();
		this.roomInfo.gameOver = false;
		this.roomInfo.countDown = this.c.maxGameTime * 60;
	}
	/**玩家加入 */
	public userJoin() {
		var user = AIUserMgr.getInstance().get(DataProl.account);
		if (user == null) {
			AIUserMgr.getInstance().createPlayer(DataProl.account, DataProl.login_data.nickName);
		}
		else {
			AIUserMgr.getInstance().resetPlayer(user);
		}

	}



	/**房间道具初始化 */
	public createRoomsProps() {
		AIPropsMgr.getInstance().createProps();
		this.roomInfo.roomProps = AIPropsMgr.getInstance().roomPorpsInit();
		this.roomInfo.roomProps = AIPropsMgr.getInstance().getRoomProps();
		// console.log(this.roomInfo.roomProps);
	};
	/**玩家进入游戏*/
	public enterRoom(user) {
		if (user == null) {
			return 0;
		}
		var airoomInfo = this.roomInfo;
		if (airoomInfo == null) {
			// console.log("房间不存在零");
			return 0;
		}
		if (airoomInfo.roomUser.length >= this.c.maxUserCountByRoom) {
			// console.log("房间人数已满");
			return 0;
		}
		if (user.isAI) {
			airoomInfo.AINumbers++;
		}
		else {
			airoomInfo.userNumbers++;
		}
		AIUserMgr.getInstance().resetPlayer(user);
		airoomInfo.roomUser.push(user);
		var position = this.getRandomPostion();
		user.x = position.x;
		user.y = position.y;
		//设置一个保护罩
		this.userMgr.setProtectShiled(user);
		//modiftyUserAIbalance(airoomInfo);

	};

	// private isHaveUser(userId) {
	// 	var isHave = false;
	// 	this.roomInfo.roomUser.forEach(e => {
	// 		if (e.userId == userId)
	// 			isHave = true;
	// 	})
	// 	return isHave;
	// }

	/**游戏开始 */
	public gameStart() {
		this.roomInfo.gameOver = true;
		//	this.moveLoop.addEventListener(egret.TimerEvent.TIMER, this.updata, this);
		//	this.moveLoop.addEventListener(egret.TimerEvent.TIMER, this.gameLoops, this);
		this.lastTime = 0;
		//	this.moveLoop.start();
	}

	/**游戏结束 */
	public gameOver() {
		//	this.moveLoop.removeEventListener(egret.TimerEvent.TIMER, this.updata, this);
		//		this.moveLoop.removeEventListener(egret.TimerEvent.TIMER, this.gameLoops, this);
		//	this.moveLoop.reset();
		/*var user=this.userMgr.get(DataProl.account)
		this.userMgr.kickUser(user);*/
		this.roomRest();
	}
	public gameLoops() {
		//进行AI的排查
		//this.balancRoomAI();
		/**让AI加入房间 */
		if (DataProl.tuanduizhan) {
			this.roomAIInit(9);
		}
		if (DataProl.isXinShou) {
			return;
		}
		else {
			this.roomAIInit(this.c.clientMinUserCountByRoom);
		}
		//模拟AI的移动和消息
		if (!DataProl.isXinShou) {
			serverAIMgr.getInstance().AIUpdate();
		}
	}
	/**上次更新时间 */
	private lastTime: number;
	/**更新 */
	public updata() {
		if (!this.roomInfo.gameOver)
			return;
		/**房间内的线 */
		var roomLine = this.roomInfo.roomLine;
		/**房间内道具 */
		var roomProps = this.roomInfo.roomProps;
		/**房间内玩家 */
		//	var roomUser = this.roomInfo.roomUser;
		var len = this.roomInfo.roomUser.length - 1;
		//采用从后到前的方式，便于
		for (var i = len; i >= 0; i--) {
			let usss = this.roomInfo.roomUser[i];
			if (usss == null) {
				return;
			}
			if (usss.userId == DataProl.account) {
				this.moveActor(usss);
			} else {
				this.movePlayer(usss);
			}
			//usss.grade += 2;
			this.GetAttributesByGrade(usss);
		}
		//将未掉线的玩家进行线的判断
		//1.根据线来判断，两头的玩家距离是否超过，或者是否有玩家掉线，或者有玩家的类型不同
		//2.判断没有线的玩家是否会产生新的线
		//3.
		LineManager.getInstance().checklines(this.roomInfo.roomUser, this.roomInfo);

		//判断线是否碰到了道具

		//	var bornNumber = AIPropsMgr.getInstance().userPorpDied(this.roomInfo.roomLine, this.roomInfo.roomProps);


		var bornNumber = AIPropsMgr.getInstance().newUserPorpDied(this.roomInfo.roomUser, this.roomInfo.roomProps);
		//releaseAllDeadProps(rooms[keys[t]].roomLine);
		//判断线是否碰到其他玩家
		this.usersCheckDeatch(this.roomInfo.roomUser, this.roomInfo);
		//将所有的吃掉的道具从房间中去掉并且重生
		if (bornNumber != null && bornNumber > 0) {
			for (var V = 0; V < bornNumber; V++) {
				AIPropsMgr.getInstance().generateProp();
				roomProps = AIPropsMgr.getInstance().getRoomProps();
				//	console.log("重生道具的个数" + bornNumber);
			}
		}
		this.deleteExtraLine(roomLine);

		var movemsg = {
			"userData": this.roomInfo.roomUser,
			"lineList": roomLine,
			"foodsList": roomProps,
			"Virus": null,
			"topData": this.roomInfo.roomUser,
		}
		if (this.c.shi) {
			this.roomInfo.roomUser.forEach(function (u) {
				if (u != null) {
					//is ai
					if (u.userId == DataProl.account) {
						AIServer.getInstance().filterTheInformation(u, movemsg);
					}
				}
			});
		}
		webNetworkMananger.getInstance().gameSceneRec.handleInformationByServer(movemsg);
	}
	/**通过分数获取(舌长、舌宽、等级)属性
	 * @param player 获取属性的对象
	 */
	public GetAttributesByGrade(player) {
		let grade = player.grade;
		/**舌宽 */
		let tongueWideData: number = 0;
		/**线长 */
		let lineLength: number = 0;
		/**等级 */
		let rank: number = 0;
		if (parseInt(grade) >= 15000) {
			tongueWideData = 15;
			lineLength = 600;
			rank = 41;
		} else if (parseInt(grade) >= 9000) {
			tongueWideData = 13;
			lineLength = 500;
			rank = 36;
		} else if (parseInt(grade) >= 7800) {
			tongueWideData = 13;
			lineLength = 460;
			rank = 35;
		} else if (parseInt(grade) >= 6600) {
			tongueWideData = 12;
			lineLength = 420;
			rank = 34;
		} else if (parseInt(grade) >= 5600) {
			tongueWideData = 12;
			lineLength = 380;
			rank = 33;
		} else if (parseInt(grade) >= 4800) {
			tongueWideData = 11;
			lineLength = 350;
			rank = 32;
		} else if (parseInt(grade) >= 4000) {
			tongueWideData = 11;
			lineLength = 320;
			rank = 31;
		} else if (parseInt(grade) >= 3200) {
			tongueWideData = 10;
			lineLength = 280;
			rank = 26;
		} else if (parseInt(grade) >= 2600) {
			tongueWideData = 10;
			lineLength = 260;
			rank = 25;
		} else if (parseInt(grade) >= 2100) {
			tongueWideData = 9;
			lineLength = 240;
			rank = 24;
		} else if (parseInt(grade) >= 1700) {
			tongueWideData = 9;
			lineLength = 220;
			rank = 23;
		} else if (parseInt(grade) >= 1300) {
			tongueWideData = 8;
			lineLength = 200;
			rank = 22;
		} else if (parseInt(grade) >= 1000) {
			tongueWideData = 8;
			lineLength = 180;
			rank = 21;
		} else if (parseInt(grade) >= 700) {
			tongueWideData = 7;
			lineLength = 150;
			rank = 16;
		} else if (parseInt(grade) >= 550) {
			tongueWideData = 7;
			lineLength = 140;
			rank = 15;
		} else if (parseInt(grade) >= 400) {
			tongueWideData = 6;
			lineLength = 130;
			rank = 14;
		} else if (parseInt(grade) >= 250) {
			tongueWideData = 6;
			lineLength = 120;
			rank = 13;
		} else if (parseInt(grade) >= 100) {
			tongueWideData = 5;
			lineLength = 110;
			rank = 12;
		} else {
			tongueWideData = 5;
			lineLength = 100;
			rank = 11;
		}
		if (rank > 20) {
			if (Math.floor(player.level / 10) < Math.floor(rank / 10)) {
				player.size *= 1.3;
			}
		}


		player.level = rank;
		player.lineLength = lineLength * frogConfig.Long_tongue_coefficient;
		/**舌宽 */
		let tongueWide = tongueWideData * frogConfig.Tongue_width_coefficient;


	}
	private deleteExtraLine(roomLine) {
		for (var l = 0; l < roomLine.length;) {
			if (roomLine[l].userOneId == -1 || roomLine[l].userTwoId == -1) {
				roomLine.splice(l, 1);
			} else {
				l++;
			}
		}
	}

	public filterTheInformation(u, movemsg) {
		let rangeEye = this.c.rangeEye;
		var filterProps = movemsg.foodsList.map(
			function (f) {
				// console.log("1111"+ t);
				var t = MathUtils.distance(f.x, f.y, u.x, u.y);
				//  console.log("1111"+ t);
				if (MathUtils.distance(f.x, f.y, u.x, u.y) < rangeEye) {
					f.isInRange = true;
				}
				else {
					f.isInRange = false;
				}
				return f;
				// if (f.x > u.x - userScreenWidth / 2 - scopeOfTheFog &&
				// 	f.x < u.x + userScreenWidth / 2 + scopeOfTheFog &&
				// 	f.y > u.y - userScreenHeigth / 2 - scopeOfTheFog &&
				// 	f.y < u.y + userScreenHeigth / 2 + scopeOfTheFog) {
				// 	return f;
				// }
			}
		).filter(function (f) { return f; });
		var filterUser = movemsg.userData.map(
			function (f) {
				if (f.userId == u.userId) {
					f.isInRange = true;
					return f;
				}
				var t = MathUtils.distance(f.x, f.y, u.x, u.y);
				//	console.log("name" + f.name + "距离" + t);
				if (MathUtils.distance(f.x, f.y, u.x, u.y) > rangeEye) {
					//return f;
					f.isInRange = false;
				}
				else {
					f.isInRange = true;
				}
				return f;
				// if (f.x > u.x - userScreenWidth / 2 - scopeOfTheFog &&
				// 	f.x < u.x + userScreenWidth / 2 + scopeOfTheFog &&
				// 	f.y > u.y - userScreenHeigth / 2 - scopeOfTheFog &&
				// 	f.y < u.y + userScreenHeigth / 2 + scopeOfTheFog) {
				// 	return f;
				// }
			}
		).filter(function (f) { return f; });

		// var filterUser = movemsg.userData.map(
		// 	function (f) {
		// 		// console.log()
		// 		if (f.x > u.x - userScreenWidth / 2 - scopeOfTheFog &&
		// 			f.x < u.x + userScreenWidth / 2 + scopeOfTheFog &&
		// 			f.y > u.y - userScreenHeigth / 2 - scopeOfTheFog &&
		// 			f.y < u.y + userScreenHeigth / 2 + scopeOfTheFog) {
		// 			if (u.name == "Clb") {
		// 				console.log("123");
		// 			}
		// 			return f;
		// 		}
		// 	}
		// ).filter(function (f) { return f; });


		movemsg.foodsList = filterProps;
		movemsg.userData = filterUser;
	}
	public usersCheckDeatch(userListTmp, room) {
		for (var t = 0; t < userListTmp.length; t++) {
			this.userCheckDied(userListTmp[t], room);
		}
	}

	public getPorpStayTime(type) {
		let tmp = 10000;
		switch (type) {
			case 1:
				tmp = this.c.propBuffReationTime.hide;
				break;
			case 2:
				tmp = this.c.propBuffReationTime.ice;
				break;
			case 3:
				tmp = this.c.propBuffReationTime.cut;
				break;
			case 4:
				tmp = this.c.propBuffReationTime.drink;
				break;
			case 8:
				tmp = this.c.propBuffReationTime.dizzy;
				break;
			case 9:
				tmp = this.c.propBuffReationTime.dizzy;
				break;
		}

		return tmp;
	}
	/**玩家检测死亡*/
	public userCheckDied(tmpuser, room) {
		var user = this.userMgr.get(tmpuser.userId);
		if (user == null)
			return;
		if (user.death.isDeath)
			return;

		let timeNow = Date.now();
		if (user.death.isDeath)
			return;
		/**判断断线处罚是否结束 */
		if ((timeNow - user.disconnection_line_time > this.c.disconnection_line_time) && user.disconnection_line_time != -1) {
			user.disconnection_line = false;
			user.disconnection_line_time = -1;
			//console.log("name"+user.name+"处罚结束")
		}
		//判断玩家的BUFF是否到期，到期则取消
		for (var i = 0; i < user.propStates.length; i++) {
			if (user.propStates[i].getPropType > 0) {
				var diftime = 0;
				/**判断道具效果是否结束 */
				diftime = timeNow - user.propStates[i].PropStartTime;
				if (diftime > this.getPorpStayTime(user.propStates[i].getPropType)) {
					user.propStates[i].getPropType = 0;
					/**yyf 添加一个if判断，去判断冰冻效果是否存在
					 * 如果冰冻效果还在则青蛙速度为0
					 */
					if (user.propStates[1].getPropType == 2) {
						user.speed = 0;
					}
					else {
						user.speed = this.c.initUserSpeed;
					}
					user.propStates[i].PropStartTime = 0;
				}

			}
		}
		//如果玩家处于保护状态，则不经过碰撞检测
		if (user.NewHandProtect.isProtect == true) {
			diftime = timeNow - user.NewHandProtect.ProtectStartTime;
			//console.log("新手时间" + Math.floor(diftime));
			if (diftime > this.c.newProtectTime) {
				//console.log("取消新手保护");
				user.NewHandProtect.isProtect = false;
				user.NewHandProtect.ProtectStartTime = 0;
			}
			else {
				return;
			}

		}
		if (user.propStates[1].getPropType == 2) {
			return;
		}
		if (DataProl.isXinShou && !user.isAI) {
			return;
		}
		var growline = Math.floor(user.lineLength * 0.05);
		/**遍历线下标列表 */

		for (var t = 0; t < room.roomLine.length; t++) {

			var oneLine = room.roomLine[t];

			if (oneLine.userOneId == user.userId || oneLine.userTwoId == user.userId) {
				continue;
			}
			var lineStartUserId = oneLine.userOneId;
			var lineEndUserId = oneLine.userTwoId;
			/**前端连线青蛙 */
			var usrstart = this.userMgr.get(lineStartUserId);
			if (usrstart == null) {
				//console.log("usrstart==null");
				continue;
			}
			/**尾端连线青蛙 */
			var usrend = this.userMgr.get(lineEndUserId);
			if (usrend == null) {
				//console.log("usrend==null");
				continue;
			}
			var userPoint = { x: user.x, y: user.y };

			/**是否是玩家自己的线*/
			if (user.id != lineStartUserId && user.id != lineEndUserId) {

				if (this.checkIsOnALine(userPoint, usrend, usrstart)) {

					// console.log("玩家:" + user.name + "  id" + user.id + "  已死亡");
					if (user.propStates[2].getPropType == 3) {
						//如果是剪刀直接回收线
						LineManager.getInstance().recoveryLine(oneLine, this);
						this.userMgr.resetPlayerOnePropStates(user, 2);
						return;
					}

					//去除玩家身上存在的线
					LineManager.getInstance().deleteLineFromPlayer(room, user);
					if (usrstart.troops != user.troops || usrstart.troops == -1) {
						usrend.grade += growline;
						usrend.lineLength = AIPropsMgr.getInstance().GetAttributesByGrade(usrend.grade).frogLineLength;
						usrend.level = AIPropsMgr.getInstance().GetAttributesByGrade(usrend.grade).level;
						usrend.killNumber++;

						usrstart.grade += growline;
						usrstart.lineLength = AIPropsMgr.getInstance().GetAttributesByGrade(usrstart.grade).frogLineLength;
						usrstart.level = AIPropsMgr.getInstance().GetAttributesByGrade(usrstart.grade).level;
						usrstart.killNumber++;
					}
					if (usrend.userId == DataProl.account || usrstart.userId == DataProl.account) {
						DataProl.totalLenght += growline;
						//usrend.killNumber ++;
						//usrstart.killNumber ++;
						//console.log("测试总长度+:" + growline);
					}
					/**青蛙死亡调用创建荷叶 */
					AIPropsMgr.getInstance().createLeaf(user.x, user.y, user.lineLength);
					this.roomUserDied(user);

				}
			}
		}
	}
	public roomUserDied(player) {
		/**如果玩家身上有线 */
		player.death.isDeath = true;
		player.death.deadStartTime = Date.now();
		if (DataProl.isXinShou) {//新手引导中AI被击杀，不会重生
			webNetworkMananger.getInstance().gameSceneRec.displayer_message(14, 700, 500);
			this.roomInfo.userNumbers--;
			return;
		}
		//AIUserMgr.getInstance().kickUser(player);
		if (player.isAI) {
			this.roomInfo.AINumbers--;
			// console.log("重建青蛙"+player.name);
			setTimeout(() => {
				this.respawnMessageManager(player.userId, player.name);
			}, 2000);

		} else {
			this.roomInfo.userNumbers--;
		}
		// this.respawnUser(player);

	}

	public myPointSub() {

	}
	private usrstarttmp = new egret.Point(0, 0);
	private usrendtmp = new egret.Point(0, 0);

	private usrendDirection = new egret.Point(0, 0);
	private usrstartDirection = new egret.Point(0, 0);



	private usrendPoint = new egret.Point(0, 0);
	private usrstartPoint = new egret.Point(0, 0);

	public checkIsOnALine(something, usrend, usrstart) {

		this.usrstarttmp.setTo(usrstart.x, usrstart.y);
		this.usrendtmp.setTo(usrend.x, usrend.y);
		/**尾端玩家方向 */
		this.usrendDirection.setTo(this.usrstarttmp.x - this.usrendtmp.x, this.usrstarttmp.y - this.usrendtmp.y);
		/**前端玩家方向 */
		this.usrendDirection.setTo(this.usrendtmp.x - this.usrstarttmp.x, this.usrendtmp.y - this.usrstarttmp.y);
		//	let usrstartDirection = this.usrendtmp.subtract(this.usrstarttmp);
		this.usrstartDirection.normalize(usrstart.size);
		this.usrendDirection.normalize(usrend.size);


		this.usrendPoint.setTo(this.usrendtmp.x + this.usrendDirection.x, this.usrendtmp.y + this.usrendDirection.y);
		/**尾端舌头点 */
		//	let usrendPoint = this.usrendtmp.add(this.usrendDirection);
		/**前端舌头点 */
		//	let usrstartPoint = this.usrstarttmp.add(this.usrstartDirection);
		this.usrstartPoint.setTo(this.usrstarttmp.x + this.usrendDirection.x, this.usrstarttmp.y + this.usrendDirection.y);

		/**点到线的距离 */
		var pointToLineLength = AIPropsMgr.getInstance().getPointToLineDistance(this.usrendPoint, this.usrstartPoint, something);

		return pointToLineLength < 50 ? true : false;
	}

	public findIndexEx(arr, userId) {
		var len = arr.length;

		while (len--) {
			if (arr[len].userId === userId) {
				return len;
			}
		}

		return -1;
	};

	private circilePointTmp0 = new egret.Point(0, 0);

	private circilePointTmp1 = new egret.Point(0, 0);
	/**圆周运动 */
	public circlingMotion(player) {
		if (player.ishadLine && player.otherLineUser != -1 && player != null) {
			/**连线者 */
			let peer = AIUserMgr.getInstance().get(player.otherLineUser);
			if (peer == null) {
				return;
			}
			/**两者之间距离 */
			let distance = MathUtils.distance(player.x, player.y, peer.x, peer.y);

			/**最大线长 */
			let lineMax = player.lineLength + peer.lineLength;
			if (distance > lineMax) {
				this.circilePointTmp0.setTo(peer.x, peer.y);
				this.circilePointTmp1.setTo(player.x, player.y);
				var rotation = Util.getInstance().calculateRotation(this.circilePointTmp0, this.circilePointTmp1);
				//	var rotation = MathUtils.getAngleEx(peer.x, peer.y, player.x, player.y);
				var hudu = rotation * Math.PI / 180;
				player.x = peer.x + Math.sin(hudu) * (lineMax);
				player.y = peer.y - Math.cos(hudu) * (lineMax);

			}
		}
	}
	/**新手引导设置青蛙位置 */
	public setPlayer(x: number, y: number) {
		var player = AIUserMgr.getInstance().get(DataProl.account);
		if (player == null || player == undefined) {
			return;
		}
		if (!player.isAI && DataProl.isXinShou) {
			player.x = x;
			player.y = y;
			player.targetdir = x + 1;
			player.targetdir = y;
		}
	}
	/**记录移动间隔时间 */
	private timeOnEnterFrame = 0;
	/**记录喝酒方向改变时间 */
	private drunkennessFrame = 0;
	/**记录喝酒方向 */
	private direction = 0;
	/**方向临时变量 */
	private dir: egret.Point = new egret.Point();
	/**玩家自己的移动 */
	public moveActor(player) {
		/**当前时间 */
		var now = egret.getTimer();
		/**上一次执行的时间 */
		var time = this.timeOnEnterFrame;
		/**时间间隔 */
		var pass = now - time;
		// console.log("onEnterFrame: ", (1000 / pass).toFixed(5), pass);
		/**移动速度 */

		var speed = player.speed * (pass / 16.66666);
		this.timeOnEnterFrame = egret.getTimer();

		if (player.targetdir == null)
			return;
		/**移动方向 */
		let vir;
		if (player.propStates[3].getPropType == 4) {
			if (Date.now() - this.drunkennessFrame >= 1000) {
				this.direction = Math.round(Math.random() * 360)
				this.drunkennessFrame = Date.now();
			}
			vir = {
				x: Math.sin(this.direction / 57.3) * 815,
				y: Math.cos(this.direction / 57.3) * 815
			};
		} else {
			vir = this.yaogan.getPosition();
		}
		if (vir == null) {
			return;
		}
		let dir = this.dir.setTo(vir.x, vir.y);// egret.Point.create(player.targetdir.x, player.targetdir.y);
		//判断玩家的射击
		this.checkShootPlayer(player);

		dir.normalize(speed);

		if (!player.isAI && DataProl.isXinShou && player.propStates[3].getPropType == 4) {//新手引导中，喝酒瞬间青蛙停止移动，3秒后恢复移动
			var diftime = 0;
			/**判断道具效果是否结束 */
			diftime = Date.now() - player.propStates[3].PropStartTime;
			if (diftime > 3000) { }
			else { return; }
		}
		if (player.isAI && DataProl.isXinShou) {
			return;
		}
		if (!isNaN(dir.y)) {
			player.y += dir.y;
		}
		if (!isNaN(dir.x)) {
			player.x += dir.x;
		}
		/**圆周运动 */
		this.circlingMotion(player);
		if (!DataProl.isXinShou) {
			if (player.x > this.c.gameWidth - 55) {
				player.x = this.c.gameWidth - 55;
			}
			if (player.y > this.c.gameHeight - 65) {
				player.y = this.c.gameHeight - 65;
			}
			if (player.x < 50) {
				player.x = 50;
			}
			if (player.y < 60) {
				player.y = 60;
			}

		}
		else {
			if (player.x > GlobalData.GameStage_width * DataProl.gameSceneScal + 100 - player.size) {
				player.x = GlobalData.GameStage_width * DataProl.gameSceneScal + 100 - player.size;
			}
			if (player.y > GlobalData.GameStage_height * DataProl.gameSceneScal + 100 - player.size) {
				player.y = GlobalData.GameStage_height * DataProl.gameSceneScal + 100 - player.size;
			}
			if (player.x < 100 + player.size) {
				player.x = 100 + player.size;
			}
			if (player.y < 100 + player.size) {
				player.y = 100 + player.size;
			}
		}

	}

	private movePlayerTmpPoint = new egret.Point(0, 0);
	/**青蛙移动 */
	public movePlayer(player) {
		if (player.targetdir == null)
			return;
		let dir = this.movePlayerTmpPoint.setTo(player.targetdir.x, player.targetdir.y);
		//判断玩家的射击
		this.checkShootPlayer(player);
		dir.normalize(player.speed);
		if (!player.isAI && DataProl.isXinShou && player.propStates[3].getPropType == 4) {//新手引导中，喝酒瞬间青蛙停止移动，3秒后恢复移动
			var diftime = 0;
			/**判断道具效果是否结束 */
			diftime = Date.now() - player.propStates[3].PropStartTime;
			if (diftime > 3000) { }
			else { return; }
		}
		if (player.isAI && DataProl.isXinShou) {
			return;
		}
		if (!isNaN(dir.y)) {
			player.y += dir.y;
		}
		if (!isNaN(dir.x)) {
			player.x += dir.x;
		}
		/**圆周运动 */
		this.circlingMotion(player);
		if (!DataProl.isXinShou) {
			if (player.x > this.c.gameWidth - 55) {
				player.x = this.c.gameWidth - 55;
			}
			if (player.y > this.c.gameHeight - 65) {
				player.y = this.c.gameHeight - 65;
			}
			if (player.x < 50) {
				player.x = 50;
			}
			if (player.y < 60) {
				player.y = 60;
			}
		}
		else {
			if (player.x > GlobalData.GameStage_width * DataProl.gameSceneScal + 100 - player.size) {
				player.x = GlobalData.GameStage_width * DataProl.gameSceneScal + 100 - player.size;
			}
			if (player.y > GlobalData.GameStage_height * DataProl.gameSceneScal + 100 - player.size) {
				player.y = GlobalData.GameStage_height * DataProl.gameSceneScal + 100 - player.size;
			}
			if (player.x < 100 + player.size) {
				player.x = 100 + player.size;
			}
			if (player.y < 100 + player.size) {
				player.y = 100 + player.size;
			}
		}

	}

	// public checkHeart(player) {

	// 	/**
	// 	 * 判断玩家是否死亡
	// 	 */
	// 	if (player.death.isDeath) {

	// 		/**
	// 		 * 如果是AI的话，则重新让其生成
	// 		 */
	// 		if (player.isAI) {
	// 			var roomInfo = this.roomInfo;
	// 			if (roomInfo != null) {
	// 				if (roomInfo.userNumbers > this.c.minxUserCountByRoom) {
	// 					return 1;
	// 				}
	// 			}
	// 			this.respawnUser(player.userId);
	// 			return 0;
	// 		}
	// 		else {
	// 			var time = Date.now() - player.death.deadStartTime;
	// 			var value = this.c.userDeathInterval;
	// 			if (time > this.c.userDeathInterval) {
	// 				return 1;
	// 			}
	// 			else {
	// 				return 0;
	// 			}
	// 		}


	// 	}
	// 	//如果是AI的话就不考虑掉线的问题
	// 	if (player.isAI) {
	// 		return 0;
	// 	}

	// 	var hearttime = Date.now() - player.lastHeartbeat;
	// 	if (hearttime > this.c.maxHeartbeatInterval) {

	// 		console.log("玩家掉线" + hearttime);
	// 		return 1;
	// 	}
	// 	return 0;
	// }

	/**
    * 获取随机的位置
    */
	public getRandomPostion() {
		if (DataProl.isXinShou) {
			return { x: GlobalData.GameStage.stageWidth / 6 * DataProl.gameSceneScal + 100, y: GlobalData.GameStage.stageHeight / 3 * DataProl.gameSceneScal + 100 };
		}
		else {
			return {
				x: this.randomInRange(serverConfig.config.gameMapBorder, this.c.gameWidth - serverConfig.config.gameMapBorder),
				y: this.randomInRange(serverConfig.config.gameMapBorder, this.c.gameHeight - serverConfig.config.gameMapBorder)
				// x: this.randomInRange(100, 1000),
				// y: this.randomInRange(100, 500)
			};
		}

	}

	public randomInRange = function (from, to) {
		return Math.floor(Math.random() * (to - from)) + from;
	};


	/**房间内AI初始化  AI加入房间 */
	public roomAIInit(AINumbers) {
		for (var t = 0; t < AINumbers; t++) {
			this.letOntAIjionRoom(t);
		}
	}
	/**更改单个AI青蛙颜色 */
	public setAitype(type) {
		for (var i = 0; i < this.roomInfo.roomUser.length; i++) {
			if (this.roomInfo.roomUser[i] != null) {
				if (this.roomInfo.roomUser[i].isAI) {
					if (!this.roomInfo.roomUser[i].ishadLine) {
						this.roomInfo.roomUser[i].frogType = type;
					}
				}
			}
		}
	}
	/**更改AI等级 */
	public setAIlevel(grade: number) {
		for (var i = 0; i < this.roomInfo.roomUser.length; i++) {
			if (this.roomInfo.roomUser[i] != null) {
				if (this.roomInfo.roomUser[i].userId == DataProl.account) {
					this.roomInfo.roomUser[i].grade = grade;
					this.roomInfo.roomUser[i].lineLength = AIPropsMgr.getInstance().GetAttributesByGrade(grade).frogLineLength;

					return;
				}
			}
		}
	}
	/**清空房间内ai*/
	public resetAi() {
		for (var i = this.roomInfo.roomUser.length - 1; i >= 0; i--) {
			if (this.roomInfo.roomUser[i] != null) {
				if (this.roomInfo.roomUser[i].isAI) {
					/**从房间内踢出ai */
					this.forceExitSpecRoom(this.roomInfo.roomUser[i], this.roomInfo)
					/**重置ai */
					//serverAIMgr.getInstance().resetAI(this.roomInfo.roomUser[i]);
				}
			}
		}
		this.roomInfo.roomUser
	}
	/**让一个AI加入房间 */
	public letOntAIjionRoom(t) {
		var ai = serverAIMgr.getInstance().getAI();
		if (ai == null) {
			return;
		}
		/**清空ai状态*/
		AIUserMgr.getInstance().resetPlayer(ai);
		if (DataProl.tuanduizhan) {//是团队战
			if (t % 2 == 0) {//多余玩家自己是黄色才行
				ai.troops = 0
			} else {
				ai.troops = 1
			}
		}
		ai.isUsed = true;
		//重新加入指定房间
		this.enterSpcRoom(ai, this.roomInfo);
	}
	/**生成一个ai青蛙 */
	public creatOneAifrog(type, point) {
		var ai = serverAIMgr.getInstance().getAI();
		if (ai == null) {
			return;
		}
		AIUserMgr.getInstance().resetPlayer(ai);
		ai.isUsed = true;
		ai.x = point.x
		ai.y = point.y
		ai.frogType = type;
		this.enterSpcRoom(ai, this.roomInfo);
	}
	/**生成一组连线ai */
	public createLinefrog(type, point1, point2, level) {
		//获取两个ai
		var ai1 = serverAIMgr.getInstance().getAI();
		var ai2 = serverAIMgr.getInstance().getAI();
		if (ai1 == null || ai2 == null) {
			return;
		}
		AIUserMgr.getInstance().resetPlayer(ai1);
		AIUserMgr.getInstance().resetPlayer(ai2);
		ai1.grade = ai2.grade = 0;
		ai1.isUsed = true;
		ai2.isUsed = true;
		ai1.x = point1.x
		ai1.y = point1.y
		ai2.x = point2.x
		ai2.y = point2.y
		ai1.frogType = ai2.frogType = type;
		/**获取一条线 */
		var line = LineManager.getInstance().getOneLine(ai1.userId, ai2.userId);
		if (line == null) {
			return;
		}
		line.userOneId = ai1.userId;
		line.userTwoId = ai2.userId;
		line.isUsed = true;
		line.type = ai2.frogType;
		line.uop = { x: ai1.x, y: ai1.y };
		line.utp = { x: ai2.x, y: ai2.y };
		//此处因为使用的是临时生成的玩家，所以改动没有意义，我们需要改动原始的数据。
		ai1.ishadLine = true;
		ai1.otherLineUser = line.userTwoId;
		ai2.ishadLine = true;
		ai1.otherLineUser = line.userOneId;
		// console.log("创建一条线");
		this.roomInfo.roomLine.push(line);
		this.enterSpcRoom(ai1, this.roomInfo);
		this.enterSpcRoom(ai2, this.roomInfo);
	}
	/**删除新手引导中一组连线青蛙 */
	public deleteLineFrog(AI1: number, AI2: number) {
		// this.roomUserDied(this.roomInfo.roomUser[1]);
		// this.roomUserDied(this.roomInfo.roomUser[2]);
		this.roomInfo.roomUser[AI1].x = this.roomInfo.roomUser[AI1].y = 4000;
		this.roomInfo.roomUser[AI1].death.isDeath = true;
		this.roomInfo.roomUser[AI1].death.deadStartTime = Date.now();
		this.roomInfo.AINumbers--;
		if (AI2 == null) {
			return;
		}
		this.roomInfo.roomUser[AI2].x = this.roomInfo.roomUser[AI2].y = 4000;
		this.roomInfo.roomUser[AI2].death.isDeath = true;
		this.roomInfo.roomUser[AI2].death.deadStartTime = Date.now();
		this.roomInfo.AINumbers--;
	}
	/**加入房间 */
	public enterSpcRoom(user, room) {

		// if (room.roomUser.length >= this.c.maxUserCountByRoom) {
		// 	console.log("房间人数已满" + room.roomUser.length);
		// 	return 1;
		// }
		if (user.roomId > 0) {
			if (room.roomId == user.roomId) {

				return 1;
			}
		}
		//AIUserMgr.getInstance().resetPlayer(user);
		user.dressup.decorateId = (user.userId == DataProl.account) ? DataProl.userCurrentDressUp.decorateId : -1;
		user.dressup.trailingId = (user.userId == DataProl.account) ? DataProl.userCurrentDressUp.trailingId : -1;
		room.roomUser.push(user);
		user.roomId = room.roomId;
		if (!DataProl.isCreateRockerPlayer && DataProl.isDoubleRocker) {
			user.name = gameGlobal.global.playerName;
			if (!DataProl.isXinShou) {
				user.frogType = AIUserMgr.getInstance().currentPlayer.frogType;
				user.x = AIUserMgr.getInstance().currentPlayer.x + 10;
				user.y = AIUserMgr.getInstance().currentPlayer.y;
			}
			user.partner = AIUserMgr.getInstance().currentPlayer.userId;
			//user.otherLineUser = user.partner;
			AIUserMgr.getInstance().currentPlayer.partner = user.userId;
			//AIUserMgr.getInstance().currentPlayer.otherLineUser = AIUserMgr.getInstance().currentPlayer.partner;
			DataProl.isCreateRockerPlayer = true;
		} else {
			if (!DataProl.isXinShou) {
				if (user.userId != DataProl.account) {
					var position = this.getRandomPostion();
					user.x = position.x;
					user.y = position.y;
				} else {
					user.x = Allvariate.getInstance().FrogPoint.x;
					user.y = Allvariate.getInstance().FrogPoint.y;
					console.log("玩家自己复活");

				}

			}
		}

		// if(!user.isAI)
		// modiftyUserAIbalance(room);
		AIUserMgr.getInstance().setProtectShiled(user);
		if (user.isAI) {
			room.AINumbers++;
		}
		else {
			room.userNumbers++;
		}
		return 0;
	}
	public respawnMessageManager(userId, name) {
		//var userId = user.userId;
		//var name = user.name;
		if (this.respawnUser(userId, name)) {

			// console.log("重建青蛙成功"+name);
			//console.log("玩家重生成功");
			var player = this.userMgr.get(userId);
			if (player == null) {
				// console.log("玩家重生中玩家不存在");
				return;
			}
			var roominfo = this.roomInfo;
			if (roominfo == null) {
				// console.log("玩家重生中房间不存在");
				return;
			}
			this.enterSpcRoom(player, roominfo);
			//设置一个保护罩
			this.userMgr.setProtectShiled(player);
			/**发送房间时间 */
			// webNetworkMananger.getInstance().gameSceneRec.startrRoomTimer();
		}
		else {
			// console.log("玩家重生失败");
		}
	}
	/**
	 * 用来处理玩家的重生
	 * 1、找到该玩家，清楚玩家死亡状态
	 * 2、在房间中重新出生该玩家
	 */
	public respawnUser(userId, name) {
		var roomInfo = this.roomInfo;
		var user = this.userMgr.get(userId);
		if (user == null) {
			// console.log("玩家重生未找到玩家");
			return false;
		}
		//重置玩家的状态
		this.userMgr.resetPlayer(user, 100);//括号添加100，清零玩家击杀数，可防止玩家重生时出现击杀的墨镜表情
		user.dressup.decorateId = (user.userId == DataProl.account) ? DataProl.userCurrentDressUp.decorateId : -1;
		user.dressup.trailingId = (user.userId == DataProl.account) ? DataProl.userCurrentDressUp.trailingId : -1;

		user.roomId = 0;
		//
		if (this.forceExitSpecRoom(user, roomInfo)) {
			// console.log("加入房间错误");
			return false;
		}
		user.name = name;
		return true;
	}
	private forceExitSpecRoom(user, room) {
		if (user == null) {
			// console.log("退出房间失败 user为空");
			return;
		}
		if (room == null) {
			// console.log("退出房间失败 玩家房间为空" + user.name);
			return;
		}
		if (Util.getInstance().findIndex(room.roomUser, user.id) > -1)
			room.roomUser.splice(Util.getInstance().findIndexEx(room.roomUser, user.userId), 1);
		if (user.isAI)
			room.AINumbers--;
		else
			room.userNumbers--;
	}
}